package com.sgb.kjwl.view.ui.adapter.enterprise;

import android.content.Context;
import android.graphics.Paint;
import android.text.TextPaint;
import android.text.TextUtils;
import android.util.Log;
import android.widget.TextView;


import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.utils.PointUtils;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class ServiceProAdapter extends BaseRecycleAdapter<Map> {
    private static final String NO_NAME = "type_name_";
    private TextView titleView;
    private TextView priceView;


    public ServiceProAdapter(Context context, List<Map> datas) {
        super(context, R.layout.item_service_pro, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final Map entity) {
        holder.setBinding(BR.viewModel, entity);
        titleView = holder.itemView.findViewById(R.id.tv_title);
        priceView = holder.itemView.findViewById(R.id.tv_price);
        TextPaint paint = priceView.getPaint();
        paint.setStyle(Paint.Style.FILL_AND_STROKE);
        paint.setStrokeWidth(1);
        String price = (String) entity.get("price");
        if (!TextUtils.isEmpty(price)) {
            priceView.setText("-1".equals(price) ? "议价" : PointUtils.price(Double.valueOf(price)) + " 元");
        }
        String title = "";
        String value1 = "";
        String value2 = "";
        String value3 = "";
        String value4 = "";
        String value5 = "";

        value1 = (String) entity.get(NO_NAME + 1);
        value2 = (String) entity.get(NO_NAME + 2);
        value3 = (String) entity.get(NO_NAME + 3);
        value4 = (String) entity.get(NO_NAME + 4);
        value5 = (String) entity.get(NO_NAME + 5);

        if (!TextUtils.isEmpty(value1))
            title = title + value1 + " | ";
        if (!TextUtils.isEmpty(value2))
            title = title + value2 + " | ";
        if (!TextUtils.isEmpty(value3))
            title = title + value3 + " | ";
        if (!TextUtils.isEmpty(value4))
            title = title + value4 + " | ";
        if (!TextUtils.isEmpty(value5))
            title = title + value5 + " | ";

       /* String key;
        String value;
        Iterator it = entity.keySet().iterator();
        while (it.hasNext()) {
            key = (String) it.next();
            if (key.equals(NO_NAME + 1)) {
                value = (String) entity.get(key);
                Log.e(key, ":" + value);
                if (!"".equals(value))
                    title = title + value + "/";
            } else if (key.equals(NO_NAME + 2)) {
                value = (String) entity.get(key);
                Log.e(key, ":" + value);
                if (!"".equals(value))
                    title = title + value + "/";
            } else if (key.equals(NO_NAME + 3)) {
                value = (String) entity.get(key);
                Log.e(key, ":" + value);
                if (!"".equals(value))
                    title = title + value + "/";
            } else if (key.equals(NO_NAME + 4)) {
                value = (String) entity.get(key);
                Log.e(key, ":" + value);
                if (!"".equals(value))
                    title = title + value + "/";
            } else if (key.equals(NO_NAME + 5)) {
                value = (String) entity.get(key);
                Log.e(key, ":" + value);
                if (!"".equals(value))
                    title = title + value + "/";
            }
        }*/
        titleView.setText(title.substring(0, title.length() - 1));
    }
}
